package com.sakura.acl;

import cn.hutool.json.JSONArray;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.ArrayList;
import java.util.List;

@SpringBootTest
public class Redistest {
    @Autowired
    RedisTemplate redisTemplate;

    @Test
    public void test01(){
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add(i);
        }
        String key = "list_key";
        String s = JSONUtil.toJsonStr(list);
        JSONArray objects = JSONUtil.parseArray(s);

        List<String> stringList = JSONUtil.toList(objects,String.class);
        System.out.println(stringList);

//        List<Integer> jsonObject = (List<Integer>) JSONUtil.parseObj(s);
//        System.out.println(jsonObject);
//        redisTemplate.opsForValue().set(key, JSONUtil.toJsonStr(list));
//        String str = String.valueOf(redisTemplate.opsForValue().get(key));
    }

    @Test
    public void test02(){
        List<Integer> list = new ArrayList<>();
        for (int i=0;i<10;i++){
            list.add(i);
        }
        String key = "list-key";
        redisTemplate.opsForValue().set(key,list);
        List<String> strList = (List<String>) redisTemplate.opsForValue().get(key);
        System.out.println(strList);
    }


}














